package com.jimmy.springcloud.service;

import com.jimmy.springcloud.entities.Dept;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * @version 1.0
 * @ ClassName DeptClientService
 * <p> 用来替换原先的bibbon+resttemplate 采用了面向接口方式调用微服务（推荐做法）
 * feign本身集成了ribbon 采用声明式接口方式
 * @ author JIMMY   （此为feign调用微服务）
 * @ Date 2020/11/17 0017 上午 11:13
 */
//@FeignClient("MICROSERVICECLOUD-DEPT")
@FeignClient(value = "MICROSERVICECLOUD-DEPT",fallbackFactory=DeptClientServiceFallbackFactory.class)    //客户端服务熔断替换了服务端的服务熔断做到了解㷒与统一的异常处理
public interface DeptClientService {
    //这些方法相当于resttempt 调用的url地址
//    @RequestMapping(value = "/sys/dept/get3/{id}", method = RequestMethod.GET)  //没有此get3 url 不能访问
//    public Dept get(@PathVariable("id") long id);
    @RequestMapping(value = "/sys/dept/get/{id}", method = RequestMethod.GET)
    public Dept get(@PathVariable("id") long id);

    @RequestMapping(value = "/sys/dept/list", method = RequestMethod.GET)
    public List<Dept> list();

    @RequestMapping(value = "/sys/dept/add", method = RequestMethod.POST)
    public boolean add(Dept dept);

//    @RequestMapping(value = "/sys/dept/get2/{id}", method = RequestMethod.GET)    //用提供者的controller方法可以调用
//    public Dept get2(@PathVariable("id") long id);

    @RequestMapping(value = "/sys/dept/get2/{id}", method = RequestMethod.GET)     //用提供者的service方法也可以调用
    public Dept getDepById(@PathVariable("id") long id);

    @RequestMapping(value = "/sys/dept/get3/{id}", method = RequestMethod.GET)     //提供者没有该接口的实现访问报路径错误
    //feign.FeignException: status 404 reading DeptClientService#get3(long); content:{"timestamp":1619246115801,"status":404,"error":"Not Found","message":"Not Found","path":"/sys/dept/get3/1"}
    public Dept get3(@PathVariable("id") long id);
}
